import axiosHttp from '@/libs/request';
import { LoginForm, Page, User, UserInfo } from '@/model';

/**
 * 登录
 * @param data 用户信息
 */
const login = (data: LoginForm) => {
  return axiosHttp.post<UserInfo>('/admin/user/login', data);
};

/**
 * 校验token
 */
const checkToken = (token: string) => {
  return axiosHttp.get<void>('/admin/user/checkToken', { token });
};

/**
 * 获取用户信息
 * @param userId 用户id
 */
const getUserInfo = (userId: number) => {
  return axiosHttp.post<UserInfo>('/admin/user/userInfo', { id: userId });
};

/**
 * 退出登录
 * @param userId 用户id
 */
const logout = (userId: number) => {
  return axiosHttp.post('/admin/user/logout', { id: userId });
};

/**
 * 获取登录方式
 */
const getLoginMode = () => {
  return axiosHttp.get('/admin/user/loginMode');
};

/**
 * 分页
 * @param data
 */
const pageUser = (data: Page<User>) => {
  return axiosHttp.post<Page<User>>('/admin/user/page', data);
};

/**
 * 创建用户
 * @param data
 */
const createUser = (data: User) => {
  return axiosHttp.post<void>('/admin/user/create', data);
};

/**
 * 更新用户
 * @param data
 */
const updateUser = (data: User) => {
  return axiosHttp.post<void>('/admin/user/update', data);
};

/**
 * 删除用户
 * @param id
 */
const deleteUser = (id: string) => {
  return axiosHttp.delete('/admin/user/delete', { id });
};

const testMessage = ()=>{
  return axiosHttp.post('/admin/user/test');
}

export {
  logout,
  checkToken,
  login,
  getUserInfo,
  getLoginMode,
  pageUser,
  createUser,
  updateUser,
  deleteUser,
  testMessage,
};
